package com.yc.bdw.Activity;

import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yc.bdw.R;
import com.yc.bdw.Utils.ListUtils;
import com.yc.bdw.model.Product;

import org.kymjs.kjframe.KJActivity;
import org.kymjs.kjframe.ui.BindView;

import java.math.BigDecimal;

public class DetailActivity extends KJActivity {
    @BindView(id = R.id.detail_back, click = true)
    private ImageView backBtn;
    @BindView(id = R.id.detail_add, click = true)
    private ImageView addBtn;
    @BindView(id = R.id.detail_buy, click = true)
    private ImageView buyBtn;
    @BindView(id = R.id.detail_collection, click = true)
    private ImageView collectionBtn;
    @BindView(id = R.id.detail_share, click = true)
    private TextView shareText;
    @BindView(id = R.id.detail_name)
    private TextView nameText;
    @BindView(id = R.id.detail_price)
    private TextView priceText;
    @BindView(id = R.id.detail_describe)
    private TextView describeText;

    @BindView(id = R.id.detail_imgs, click = true)
    private View imgsView;
    @BindView(id = R.id.detail_reviews, click = true)
    private View reviewsView;
    @BindView(id = R.id.detail_info)
    private LinearLayout infoLayout;
    @BindView(id = R.id.detail_activity)
    private LinearLayout activityLayout;
    @BindView(id = R.id.detail_activity_name)
    private TextView activityNameText;

    private Product product;
    private Boolean isCollected = false;
    private String infos = "商品编号：tz00333,包装类型：单瓶装,酒精度：14度";

    @Override
    public void setRootView() {
        setContentView(R.layout.activity_commodity_detail);
    }

    @Override
    public void initData() {
        super.initData();

        init();
    }

    private void init() {
        product = new Product();
        product.setName("酒");
        product.setActivityName("团购");
        product.setPrice(new BigDecimal(22));
        product.setDescribe("720ml，品质保证");
    }

    @Override
    public void initWidget() {
        super.initWidget();

        nameText.setText(product.getName());
        priceText.setText("￥"+product.getPrice());
        describeText.setText(product.getDescribe());
        if ( product.getActivityName() != null ) {
            activityLayout.setVisibility(View.VISIBLE);
            activityNameText.setText(product.getActivityName()+":");
        }
        infoInit();
    }

    private void infoInit() {
        String[] infoArray = infos.split(",");
        for ( int i = 0; i < infoArray.length; i++ ) {
            if ( !"".equals(infoArray[i]) ) {
                TextView item = new TextView(aty);
                item.setText(infoArray[i]);
                item.setGravity(Gravity.CENTER_VERTICAL);
                item.setTextColor(getResources().getColor(R.color.text));
                item.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
                infoLayout.addView(item, ViewGroup.LayoutParams.MATCH_PARENT, ListUtils.dip2px(aty,30));
            }
        }
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
            case R.id.detail_back:
                finish();
                break;
            case R.id.detail_collection:
                if ( isCollected ) {
                    isCollected = false;
                    collectionBtn.setBackgroundResource(R.drawable.btn_follow);
                } else {
                    isCollected = true;
                    collectionBtn.setBackgroundResource(R.drawable.btn_follow_pre);
                }
                break;
            case R.id.detail_add:
                break;
            case R.id.detail_buy:
                break;
            case R.id.detail_share:
                break;
            case R.id.detail_imgs:
                break;
            case R.id.detail_reviews:
                break;
        }
    }
}
